package com.zh.impl;

import com.zh.pojo.domain.DriverPoint;
import com.zh.remote.api.BigdataApi;
import com.zh.remote.pojo.param.DriverPointResult;
import com.zh.result.JSONResult;
import com.zh.service.IDriverPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 远程调用BigdataApi对象 ，并实现 BigdataApi接口
 */
@RestController
public class RemoteBigdataApiImpl implements BigdataApi {

    @Autowired
    private IDriverPointService pointService;

    /**
     * 查询司机坐标
     *
     * @param orderNo 订单号
     * @return
     */
    @Override
    public JSONResult<List<DriverPointResult>> selectDriverPointByOrderNo(String orderNo) {
        List<DriverPoint> driverPoints = pointService.selectDriverPointByOrderNo(orderNo);
        if (driverPoints != null && !driverPoints.isEmpty()) {
            List<DriverPointResult> pointResultList = driverPoints.stream().map(driverPoint ->
                    new DriverPointResult(driverPoint.getLongitude(), driverPoint.getLatitude())
            ).collect(Collectors.toList());
            return JSONResult.success(pointResultList);
        }
        return JSONResult.success();
    }
}
